﻿using MvcApplication.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MvcApplication.Converter
{
    public static class EntityToDtoConverter
    {
        public static UserInfoDto ToDto(this UserInfo source)
        {
            if (source == null) return null;

            return new UserInfoDto
            {
                IsAdmin = source.IsAdmin,
                FullName = source.FullName,
                ID = source.ID,
                Menus = source.Roles.SelectMany(t => t.RoleMenus.Select(s => s.ToDto())).ToList()
            };
        }

        public static MenuDto ToDto(this RoleMenu source)
        {
            if (source == null) return null;
            return new MenuDto
            {
                RoleID = source.RoleID,
                CanView = source.CanView,
                CanEdit = source.CanEdit,
                CanDelete = source.CanDelete,
                Menu = source.Menu
            };
        }
    }
}
